﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using bzxxxt.bll;
using bzxxxt.dal;
using bzxxxt.model;

namespace bzxxxt.admin.ashx
{
    /// <summary>
    /// bg_ecobural 的摘要说明
    /// </summary>
    public class bg_ecobural : admin.ashx.rm_base
    {
        EcoBuralBLL buralBLL = new EcoBuralBLL();
        public override void add(HttpContext context)
        {
            string pcode = context.Request.Params["ui_ecobural_paradise_code"];

            string deadId = context.Request.Params["ui_ecobural_dead_id"];
            string storeType = context.Request.Params["ui_ecobural_storetype"];
            string deadName = context.Request.Params["ui_ecobural_dead_name"];
            string deadCardNo = context.Request.Params["ui_ecobural_dead_cardno"];
            string deadGender = context.Request.Params["ui_ecobural_dead_gender"];
            string deadNation = context.Request.Params["ui_ecobural_dead_nation"];
            string deadArea = context.Request.Params["ui_ecobural_dead_areaId"];
            string relation = context.Request.Params["ui_ecobural_relative_relation"];
            string fireTime = context.Request.Params["ui_ecobural_dead_firetime"];
            string addr = context.Request.Params["ui_ecobural_dead_addr"];

            EcoBuralModel eco = new EcoBuralModel();

            eco.paradisecode = pcode;

            if (!string.IsNullOrEmpty(deadId))
            {
                eco.deadId = int.Parse(deadId);
            }

            
            eco.deadName = deadName;
            eco.deadGender = deadGender;
            eco.deadCardno = deadCardNo;
            eco.deadNation = deadNation;
            eco.relation = relation;
            eco.storetype = storeType;
            eco.deadAreaCode = deadArea;
            eco.deadHomeAddr = addr;
            if (!string.IsNullOrEmpty(fireTime))
            {
                eco.deadFireTime = DateTime.Parse(fireTime);
            }
            
            string relativeId = context.Request.Params["ui_ecobural_relative_id"];
            string rName = context.Request.Params["ui_ecobural_relative_name"];
            string rTel = context.Request.Params["ui_ecobural_relative_tel"];
            string rArea = context.Request.Params["ui_ecobural_relative_areaId"];
            string rCardno = context.Request.Params["ui_ecobural_relative_cardno"];


            if (!string.IsNullOrEmpty(relativeId))
            {
                eco.relativeId = int.Parse(relativeId);
            }
            eco.relativeName= rName;
            eco.relativeTel = rTel;
            eco.reltiveAreaCode = rArea;
            eco.areacode = deadArea;
            eco.reltiveCardNo = rCardno;
                                    
            context.Response.Write(buralBLL.Add(eco));
        }

        public override void edit(HttpContext context)
        {

            string id = context.Request.Params["ui_ecobural_id"];
            string pcode = context.Request.Params["ui_ecobural_paradise_code"];

            string deadId = context.Request.Params["ui_ecobural_dead_id"];
            string storeType = context.Request.Params["ui_ecobural_storetype"];
            string deadName = context.Request.Params["ui_ecobural_dead_name"];
            string deadCardNo = context.Request.Params["ui_ecobural_dead_cardno"];
            string deadGender = context.Request.Params["ui_ecobural_dead_gender"];
            string deadNation = context.Request.Params["ui_ecobural_dead_nation"];
            string deadArea = context.Request.Params["ui_ecobural_dead_areaId"];
            string relation = context.Request.Params["ui_ecobural_relative_relation"];
            string fireTime = context.Request.Params["ui_ecobural_dead_firetime"];
            string addr = context.Request.Params["ui_ecobural_dead_addr"];

            EcoBuralModel eco = new EcoBuralModel();
            eco.id = int.Parse(id);
            eco.paradisecode = pcode;

            if (!string.IsNullOrEmpty(deadId))
            {
                eco.deadId = int.Parse(deadId);
            }
            if (!string.IsNullOrEmpty(fireTime))
            {
                eco.deadFireTime = DateTime.Parse(fireTime);
            }

            eco.deadName = deadName;
            eco.deadGender = deadGender;
            eco.deadCardno = deadCardNo;
            eco.deadNation = deadNation;
            eco.relation = relation;
            eco.storetype = storeType;
            eco.deadAreaCode = deadArea;
            eco.deadHomeAddr = addr;

            string relativeId = context.Request.Params["ui_ecobural_relative_id"];
            string rName = context.Request.Params["ui_ecobural_relative_name"];
            string rTel = context.Request.Params["ui_ecobural_relative_tel"];
            string rArea = context.Request.Params["ui_ecobural_relative_areaId"];
            string rCardno = context.Request.Params["ui_ecobural_relative_cardno"];


            if (!string.IsNullOrEmpty(relativeId))
            {
                eco.relativeId = int.Parse(relativeId);
            }
            eco.relativeName = rName;
            eco.relativeTel = rTel;
            eco.reltiveAreaCode = rArea;
            eco.areacode = deadArea;
            eco.reltiveCardNo = rCardno;

            context.Response.Write(buralBLL.Edit(eco));
        }

        public override void delete(HttpContext context)
        {
            string id = context.Request.Params["id"];
            context.Response.Write(buralBLL.Delete(int.Parse(id)));
        }

        public override void getall(HttpContext context)
        {
            string where = context.Request.Params["where"] ?? "1=1";
            int pageIndex = CommUtil.GetPageIndex(context);
            int pageSize = CommUtil.GetPageSize(context);
            string mySort = CommUtil.GetSort(context) + " " + CommUtil.GetOrder(context);

            context.Response.Write(buralBLL.GetListByPage(pageSize, pageIndex, mySort, where));
        }

        public override void search(HttpContext context)
        {
            string where = context.Request.Params["where"] ?? "1=1";
            int pageIndex = CommUtil.GetPageIndex(context);
            int pageSize = CommUtil.GetPageSize(context);
            string mySort = CommUtil.GetSort(context) + " " + CommUtil.GetOrder(context);

            context.Response.Write(buralBLL.GetListByPage(pageSize, pageIndex, mySort, where));
        }
        public override void other(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request.Params["action"];

            
        }
    }
}